<?php

include_once 'Classes/PHPCodeProvider.php';

/*
 * Create an instance of the CodeGeneratorOptions class
 * using the default options for code generation.
 */

$options = new CodeGeneratorOptions();

/*
 * Create an instance of the IndentedTextWriter.
 * After the generateCodeFromExpression call
 * $writer will hold the generated code.
 */

$writer = new IndentedTextWriter();

/*
 * Create an instance of a class named 'SuperMemo'
 * passing no arguments to the constructor
 */

$createSuperMemo = new ObjectCreateExpression(new TypeReference('SuperMemo'));

/*
 * Generate the code and output the result.
 */

$provider = new PHPCodeProvider();

$provider->generateCodeFromExpression($createSuperMemo, $writer, $options);

echo 
    '<pre>' . str_replace(
        '<br />', '', highlight_string($writer->get_String(), true)) . 
    '<pre/>';

$writer->clear();

/*
 * Create an instance of a class named 'Combination'
 * Passing four arguments: $first, $second, $third and $fourth.
 */

$createCombination = new ObjectCreateExpression(new TypeReference('Combination'));
$createCombination->Parameters->add(new VariableReferenceExpression('first'));
$createCombination->Parameters->add(new VariableReferenceExpression('second'));
$createCombination->Parameters->add(new VariableReferenceExpression('third'));
$createCombination->Parameters->add(new VariableReferenceExpression('fourth'));

$provider->generateCodeFromExpression($createCombination, $writer, $options);

echo 
    '<pre>' . str_replace(
        '<br />', '', highlight_string($writer->get_String(), true)) . 
    '<pre/>';

/*
 * The output should be:
 * 
 * new SuperMemo()
 *
 * new Combination($first, $second, $third, $fourth)
 * 
 */

?>
